﻿using System;
using System.Collections.Generic;
using DLM.Infrastructure.Domain;
using System.ComponentModel.DataAnnotations;

namespace DLM.Domain.Model
{
    public class Bonus : IValidatableObject, IAggregateRoot
    {
        public int BonusID { get; set; }
        public int UserID { get; set; }

        [Required(ErrorMessage = "积分值不予续为空")]
        [RegularExpression(@"^(-?\d+)(\.\d+)?$", ErrorMessage = "请输入正确的积分值！")]
        public Nullable<decimal> Bonuses { get; set; }

        [DataType(DataType.DateTime, ErrorMessage = "日期格式不正确")]
        public Nullable<DateTime> UpdateDate { get; set; }

        [DataType(DataType.DateTime, ErrorMessage = "日期格式不正确")]
        public DateTime CreateDate { get; set; }

        public virtual User User { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!Bonuses.HasValue)
            {
                yield return new ValidationResult("积分不允许为空！");
            }
        }
    }
}
